package com.wanmait.wanmarecruit.webController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.ApplyPosition;
import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.service.ApplyPositionService;
import com.wanmait.wanmarecruit.service.NoticeService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("web")
public class WebPersonalApplicationsController {

    @Resource
    private ApplyPositionService applyPositionService;
    @Resource
    private NoticeService noticeService;

    //去个人主页申请工作进度页面
    @RequestMapping("/personal/homepage/personalApplicationsJobs")
    public ModelAndView goPersonalApplicationsJobs(HttpSession session)
    {
        Integer userId = ((User)session.getAttribute("user")).getId();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("notices",noticeService.selectAllNoticeByUser(userId,1,10));
        modelAndView.addObject("numOfNotice",noticeService.getAllNoticeNotRead(userId));
        return modelAndView;
    }
    //Ajax通过userId查询所有的申请工作表
    @RequestMapping("/personal/homepage/personalApplicationsJobsData")
    @ModelAttribute("ApplyPositionPageInfo")
    public PageInfo<ApplyPosition> selectAllApplicationByUserId(HttpServletRequest request,Integer pageNum, String keyword)
    {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        Integer userId=user.getId();
        if(pageNum==0)
        {
            pageNum=1;
        }
        Integer pageSize=5;
        return applyPositionService.selectAllApplicationJobsByUserId(pageNum,pageSize,userId,keyword);
    }
    //ajax通过applyPositionId删除一个申请工作表(张佳炜)
    @RequestMapping("/personal/homepage/deleteOneByApplyPositionId")
    @ResponseBody
    public void deleteOneByApplyPositionId(Integer applyPositionId)
    {
        applyPositionService.deleteOneByApplyPositionId(applyPositionId);
    }
    //ajax通过applyPositionIds删除多个申请工作表（张佳炜）
    @RequestMapping("/personal/homepage/deleteSelectByApplyPositionIds")
    @ResponseBody
    public void deleteSelectByApplyPositionIds(String applyPositionIds)
    {
        applyPositionService.deleteSelectByApplyPositionIds(applyPositionIds);
    }
}
